package br.pucrio.inf.csm.matchers.schema;

import br.pucrio.inf.csm.Attribute;
import br.pucrio.inf.csm.Catalog;
import br.pucrio.inf.csm.IMatch;
import br.pucrio.inf.csm.QueryOccurrenceMatrix;

/**
 * Executes schema-matching of attributes and taxonomies of a mediator against
 * an ordinary data source.
 * 
 * @author agazola
 * 
 */
public class MutualInformationSchemaMatcher extends
		AbstractCatalogSchemaMatcher {

	@Override
	public IMatch<Attribute> matchAttributes(Catalog globalCatalog,
			Catalog dataSourceCatalog) {
		// occurrence matrix for [globalCatalog schema x dataSourceCatalog
		// schema]
		long initialTime = System.currentTimeMillis();
		QueryOccurrenceMatrix occurrenceMatrix = buildOccurrenceMatrix(
				globalCatalog, dataSourceCatalog);
		long finalTime = System.currentTimeMillis();
		System.out.println("Tempo total para fazer matriz de ocorrencia: "
				+ (finalTime - initialTime));

		/*
		 * occurrenceMatrix.set(0, 0, 10879); occurrenceMatrix.set(0, 1, 180);
		 * occurrenceMatrix.set(0, 2, 0); occurrenceMatrix.set(0, 3, 65);
		 * occurrenceMatrix.set(0, 4, 119721); occurrenceMatrix.set(0, 5,
		 * 120716); occurrenceMatrix.set(0, 6, 74028); occurrenceMatrix.set(0,
		 * 7, 2835);
		 * 
		 * occurrenceMatrix.set(1, 0, 200); occurrenceMatrix.set(1, 1, 0);
		 * occurrenceMatrix.set(1, 2, 0); occurrenceMatrix.set(1, 3, 74);
		 * occurrenceMatrix.set(1, 4, 11646); occurrenceMatrix.set(1, 5, 39761);
		 * occurrenceMatrix.set(1, 6, 0); occurrenceMatrix.set(1, 7, 96);
		 * 
		 * occurrenceMatrix.set(2, 0, 1107); occurrenceMatrix.set(2, 1, 3014);
		 * occurrenceMatrix.set(2, 2, 0); occurrenceMatrix.set(2, 3, 0);
		 * occurrenceMatrix.set(2, 4, 2181); occurrenceMatrix.set(2, 5, 1310);
		 * occurrenceMatrix.set(2, 6, 0); occurrenceMatrix.set(2, 7, 2427);
		 * 
		 * occurrenceMatrix.set(3, 0, 4174); occurrenceMatrix.set(3, 1, 534);
		 * occurrenceMatrix.set(3, 2, 0); occurrenceMatrix.set(3, 3, 0);
		 * occurrenceMatrix.set(3, 4, 1033); occurrenceMatrix.set(3, 5, 1167);
		 * occurrenceMatrix.set(3, 6, 0); occurrenceMatrix.set(3, 7, 84242);
		 * 
		 * occurrenceMatrix.set(4, 0, 10879); occurrenceMatrix.set(4, 1, 10879);
		 * occurrenceMatrix.set(4, 2, 10879); occurrenceMatrix.set(4, 3, 10879);
		 * occurrenceMatrix.set(4, 4, 10879); occurrenceMatrix.set(4, 5, 10879);
		 * occurrenceMatrix.set(4, 6, 10879); occurrenceMatrix.set(4, 7, 10879);
		 * 
		 * 
		 * occurrenceMatrix.set(5, 0, 10879); occurrenceMatrix.set(5, 1, 10879);
		 * occurrenceMatrix.set(5, 2, 10879); occurrenceMatrix.set(5, 3, 10879);
		 * occurrenceMatrix.set(5, 4, 10879); occurrenceMatrix.set(5, 5, 10879);
		 * occurrenceMatrix.set(5, 6, 10879); occurrenceMatrix.set(5, 7, 10879);
		 * 
		 * occurrenceMatrix.set(6, 0, 10879); occurrenceMatrix.set(6, 1, 10879);
		 * occurrenceMatrix.set(6, 2, 10879); occurrenceMatrix.set(6, 3, 10879);
		 * occurrenceMatrix.set(6, 4, 10879); occurrenceMatrix.set(6, 5, 10879);
		 * occurrenceMatrix.set(6, 6, 10879); occurrenceMatrix.set(6, 7, 10879);
		 * 
		 * occurrenceMatrix.set(7, 0, 10879); occurrenceMatrix.set(7, 1, 10879);
		 * occurrenceMatrix.set(7, 2, 10879); occurrenceMatrix.set(7, 3, 10879);
		 * occurrenceMatrix.set(7, 4, 10879); occurrenceMatrix.set(7, 5, 10879);
		 * occurrenceMatrix.set(7, 6, 10879); occurrenceMatrix.set(7, 7, 10879);
		 */

		/*GenericMatrix mutualInformation = new GenericMatrix(dataSourceCatalog
				.getSchema(), globalCatalog.getSchema());
		
		mutualInformation.set(0, 0, 8.848846059910582E-4);
		mutualInformation.set(0, 1, 4.227763215717996E-6);
		mutualInformation.set(0, 2, 0.0);
		mutualInformation.set(0, 3, 0.0);
		mutualInformation.set(0, 4, -7.739489341853866E-4);
		mutualInformation.set(0, 5, -9.403166780470086E-4);
		mutualInformation.set(0, 6, 0.0070498832203398825);
		mutualInformation.set(0, 7, 3.822243577787563E-5);
		
		mutualInformation.set(1, 0, 6.0935100058074815E-6);
		mutualInformation.set(1, 1, 0.0);
		mutualInformation.set(1, 2, 0.0);
		mutualInformation.set(1, 3, 9.179073945752482E-6);
		mutualInformation.set(1, 4, -2.084042817530789E-4);
		mutualInformation.set(1, 5, 3.83809061180207E-4);
		mutualInformation.set(1, 6, 0.0);
		mutualInformation.set(1, 7, -2.2011713086129388E-6);
		
		mutualInformation.set(2, 0, 1.2155863059618256E-4);
		mutualInformation.set(2, 1, 5.207199424085724E-4);
		mutualInformation.set(2, 2, 0.0);
		mutualInformation.set(2, 3, 0.0);
		mutualInformation.set(2, 4, -4.082097399839211E-5);
		mutualInformation.set(2, 5, -4.2319447413214326E-5);
		mutualInformation.set(2, 6, 0.0);
		mutualInformation.set(2, 7, 2.2418506607792867E-4);
		
		mutualInformation.set(3, 0, 3.715070182384393E-4);
		mutualInformation.set(3, 1, 4.249281702181844E-5);
		mutualInformation.set(3, 2, 0.0);
		mutualInformation.set(3, 3, 0.0);
		mutualInformation.set(3, 4, -9.15560299920065E-5);
		mutualInformation.set(3, 5, -1.0183784272458682E-4);
		mutualInformation.set(3, 6, 0.0);
		mutualInformation.set(3, 7, 0.01045586243663599);
		
		mutualInformation.set(4, 0, -4.810262767963306E-5);
		mutualInformation.set(4, 1, 0.0);
		mutualInformation.set(4, 2, 0.0);
		mutualInformation.set(4, 3, 0.0);
		mutualInformation.set(4, 4, 0.007605689924128018);
		mutualInformation.set(4, 5, -0.00562401054867704);
		mutualInformation.set(4, 6, 0.0);
		mutualInformation.set(4, 7, 0.0);
		
		mutualInformation.set(5, 0, -5.8474761522131794E-5);
		mutualInformation.set(5, 1, 0.0);
		mutualInformation.set(5, 2, 1.1193162440643367E-5);
		mutualInformation.set(5, 3, 0.0);
		mutualInformation.set(5, 4, 0.010860535125481238);
		mutualInformation.set(5, 5, -0.008086889409182903);
		mutualInformation.set(5, 6, 0.0);
		mutualInformation.set(5, 7, 0.0);
		
		mutualInformation.set(6, 0, -9.939957830094791E-6);
		mutualInformation.set(6, 1, 0.0);
		mutualInformation.set(6, 2, 0.0);
		mutualInformation.set(6, 3, 0.0);
		mutualInformation.set(6, 4, -0.009146522958343827);
		mutualInformation.set(6, 5, 0.017210960863983542);
		mutualInformation.set(6, 6, 0.0);
		mutualInformation.set(6, 7, 0.0);
		
		mutualInformation.set(7, 0, -1.254978894207147E-5);
		mutualInformation.set(7, 1, 0.0);
		mutualInformation.set(7, 2, 0.0);
		mutualInformation.set(7, 3, 0.0);
		mutualInformation.set(7, 4, -0.0015995878590825319);
		mutualInformation.set(7, 5, 0.0023292402548473496);
		mutualInformation.set(7, 6, 0.0);
		mutualInformation.set(7, 7, 0.0);
			
		return mutualInformation.findMatches();*/

		return occurrenceMatrix.computeMutualInformationMatrix().findMatches();
	}
}
